import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
 * @author Miracle Luna
 * @version 1.0
 * @date 2019/7/3 18:55
 */
public class Base64Utils
{
    final static Base64.Encoder encoder = Base64.getEncoder();
    final static Base64.Decoder decoder = Base64.getDecoder();

    /**
     * 给字符串加密
     *
     * @param text
     * @return
     */
    public static String encode(String text)
    {
        return encoder.encodeToString(text.getBytes(StandardCharsets.UTF_8));
    }

    /**
     * 将加密后的字符串进行解密
     *
     * @param encodedText
     * @return
     */
    public static String decode(String encodedText)
    {
        return new String(decoder.decode(encodedText), StandardCharsets.UTF_8);
    }

    /**
     * @Description:
     * @Param:
     * @return:
     * @Author: 朝花不迟暮
     * @Date: 2020/5/2

    public static void main(String[] args)
    {

    String username = "Miracle Luna";
    String password = "p@sSW0rd";

    // 加密
    System.out.println("====  [加密后] 用户名/密码  =====");
    System.out.println(Base64Utils.encode(username));
    System.out.println(Base64Utils.encode(password));

    // 解密
    System.out.println("\n====  [解密后] 用户名/密码  =====");
    System.out.println(Base64Utils.decode(Base64Utils.encode(username)));
    System.out.println(Base64Utils.decode(Base64Utils.encode(password)));
    }
     */
}